<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	template="/WEB-INF/templates/default.xhtml"
 	xmlns:sec="http://www.springframework.org/security/facelets/tags">  
	<ui:define name="content">

		<!-- Formulário de Pesquisa -->
		<h:form id="frmPesquisa" styleClass="form-horizontal" prependId="false">
			<p:outputPanel id="panelPesquisa" rendered="#{!acompanharChamadoController.mostraCadastro}">
				<fieldset>
					<legend>#{messages.TITLE_ACOMPANHAR_CHAMADO}</legend>
	
					<!-- Campos de Pesquisa -->
					<div class="control-group">
					<h:outputLabel for="cmbDepartamentoSearch" value="#{messages.LABEL_DEPARTAMENTO}:" styleClass="control-label"/>
						<div class="controls">
							<h:selectOneMenu id="cmbDepartamentoSearch" value="#{acompanharChamadoController.chamadoSearch.departamento}" label="#{messages.LABEL_DEPARTAMENTO}"
								converter="entityConverter">
								<f:selectItem itemLabel="Selecione o #{messages.LABEL_DEPARTAMENTO}"/>
								<f:selectItems value="#{acompanharChamadoController.departamentosPesquisa}" var="departamento" itemLabel="#{departamento.nome}"/>
							</h:selectOneMenu>
						</div>
					</div>
					<!--End Campos de Pesquisa -->
	
					<!-- Primeiro Grupo de botões -->
					<div class="form-actions">
						<p:commandButton id="btnPesquisar" value="#{messages.LABEL_PESQUISAR}" action="#{acompanharChamadoController.pesquisar()}"
							process="frmPesquisa" update="frmPesquisa" styleClass="btn btn-primary"/>
							
						<p:commandButton id="btnLimpar" value="#{messages.LABEL_LIMPAR}" action="#{acompanharChamadoController.limpar()}"
							process="@this" update="frmPesquisa" styleClass="btn btn-primary"/>
	                </div>
	                <!--End Primeiro Grupo de botões -->
				</fieldset>
	
				<!-- Grid de dados -->
				<p:dataTable id="tblChamado" var="chamado" value="#{acompanharChamadoController.chamados}" rows="10" paginator="true" 
	           		style="#{empty acompanharChamadoController.chamados ? 'display:none;' : 'display:table; width: 100%;'}" styleClass="table table-bordered">

	             	<f:facet name="header">
	             		<h:outputText value="#{messages.TITLE_PESQUISAR}"/>
	     			</f:facet>

					<p:column headerText="#{messages.LABEL_RESUMO}" >  
	                    <h:outputText value="#{chamado.resumo}"/>
	                </p:column>
	                
	                <p:column headerText="#{messages.LABEL_DESCRICAO_PROBLEMA}" >  
	                    <h:outputText value="#{chamado.descricao}"/>
	                </p:column>

					<p:column headerText="#{messages.LABEL_SOLICITANTE}" >
	                    <h:outputText value="#{chamado.usuarioSolicitacao.nome}"/>
	                </p:column>

					<p:column headerText="#{messages.LABEL_UNIDADE}" >  
	                    <h:outputText value="#{chamado.unidade.nome}"/>
	                </p:column>

	     			<p:column headerText="#{messages.LABEL_DEPARTAMENTO}" >  
	                    <h:outputText value="#{chamado.departamento.nome}"/>
	                </p:column>

					<!-- Segundo Grupo de botões -->
					<p:column headerText="#{messages.LABEL_STATUS}" style="text-align: center !important;">
						 <h:outputText value="Aprovado" rendered="#{chamado.situacao == 1}" styleClass="color-green"/>
						 <h:outputText value="Reprovado" rendered="#{chamado.situacao == 0}" styleClass="color-red"/>
	                </p:column>

					<p:column headerText="#{messages.LABEL_EXECUTAR}" style="text-align: center !important;"
						rendered="#{usuarioBean.isTecnico() or usuarioBean.isGerente() or usuarioBean.isAdministrador()}">
						<div style="#{chamado.situacao == 0 ? 'display: none;' : ''}">
							<p:commandLink id="btnExecutar" title="#{messages.LABEL_EXECUTAR}" oncomplete="modalExecutar.show()" process="@this"
		                		update=":frmPesquisa" rendered="#{chamado.isAgendado == 1}">
		                		<f:setPropertyActionListener value="#{chamado}" target="#{acompanharChamadoController.chamado}"/>
		                		<p:graphicImage value="#{resource['images/circle_green.png']}" />
		                	</p:commandLink>
	
		                	<p:commandLink id="btnExecutarException" title="#{messages.LABEL_EXECUTAR}" action="#{acompanharChamadoController.validarChamado(chamado)}"
		                		process="@this" update=":frmPesquisa" rendered="#{chamado.isAgendado == 0}">
		                		<p:graphicImage value="#{resource['images/circle_red.png']}" />
		                	</p:commandLink>
		                </div>
	                </p:column>

	                <p:column headerText="#{messages.LABEL_AGENDAR}" style="text-align: center !important;"
	                	rendered="#{usuarioBean.isTecnico() or usuarioBean.isGerente() or usuarioBean.isAdministrador()}">
						<p:commandLink id="btnAgendar" title="#{messages.LABEL_AGENDAR}" update=":frmAgenda" oncomplete="modalAgenda.show()"
	                		rendered="#{chamado.situacao == 1 and chamado.isAgendado == 0}" actionListener="#{acompanharChamadoController.inicializarObjetos(chamado)}">
	                		<p:graphicImage value="#{resource['images/calendar.png']}" />
	                	</p:commandLink>

	                	<p:commandLink id="btnReprovado" title="#{messages.LABEL_AGENDAR}" action="#{acompanharChamadoController.validarAgendamento(chamado)}"
	                		process="@this" update=":frmPesquisa" rendered="#{chamado.situacao == 0}">
	                		<f:setPropertyActionListener value="#{chamado}" target="#{acompanharChamadoController.chamado}"/>
	                		<p:graphicImage value="#{resource['images/circle_red.png']}" />
	                	</p:commandLink>

						<h:outputText value="-" rendered="#{chamado.isAgendado == 1}"/>
	                </p:column>
	                <!-- End Segundo Grupo de botões -->
				</p:dataTable>
				<!-- End Grid de dados -->
			</p:outputPanel>
		</h:form>
		<!-- End Formulário de Pesquisa -->
		
		<!-- Dialog de confirmação ações -->
       	<p:dialog widgetVar="modalExecutar" header="#{messages.TITLE_HEADER_EXECUTAR}" resizable="false" modal="true">
			<h:form id="frmExecutar" prependId="false">
				<div class="control-group">
					<h:outputLabel for="txtResumoExecucao" value="#{messages.LABEL_RESUMO}:" styleClass="control-label"/>
                    <div class="controls">
						<p:inputTextarea id="txtResumoExecucao" value="#{acompanharChamadoController.chamado.resumoExecucao}"
							label="#{messages.LABEL_RESUMO}" style="width: 535px;"/>
					</div>
				</div>
				
				<div class="form-actions">
					<p:commandButton value="#{messages.BTN_SALVAR}" process="@this" actionListener="#{acompanharChamadoController.executar()}"
						onclick="confirmModalExecutar.hide();" styleClass="btn" update=":frmPesquisa" oncomplete="Util.scrollTop();"/>
	                	
	                <p:commandButton value="#{messages.LABEL_CANCELAR}" styleClass="btn" type="button" onclick="modalExecutar.hide();"/>
				</div>
			</h:form>
		</p:dialog>
		
		<p:dialog widgetVar="modalAgenda" header="#{messages.TITLE_HEADER_AGENDAR}" resizable="false" modal="true">
			<h:form id="frmAgenda" prependId="false">
				<p:messages autoUpdate="true"></p:messages>
			
				<div class="control-group">
					<h:outputLabel for="txtResumoChamado" value="#{messages.LABEL_RESUMO}:" styleClass="control-label required"/>
	                   <div class="controls">
						<p:inputText id="txtResumoChamado" value="#{acompanharChamadoController.agenda.chamado.resumo}"
							maxlength="50" label="#{messages.LABEL_RESUMO}" styleClass="input-xxlarge" disabled="true"/>
					</div>
				</div>
	
				<div class="control-group">
					<h:outputLabel for="txtDataInicio" value="#{messages.LABEL_DATA_INICIO}:" styleClass="control-label required"/>
	                   <div class="controls">
						<p:calendar id="txtDataInicio" value="#{acompanharChamadoController.agenda.dataInicio}" showOn="button"
							pattern="dd/MM/yyyy" locale="pt"/>
					</div>
				</div>

				<div class="control-group">
					<h:outputLabel for="txtDataFim" value="#{messages.LABEL_DATA_FIM}:" styleClass="control-label required"/>
	                   <div class="controls">
						<p:calendar id="txtDataFim" value="#{acompanharChamadoController.agenda.dataFim}" showOn="button"
							pattern="dd/MM/yyyy" locale="pt"/>
					</div>
				</div>
	
				<div class="control-group">
					<h:outputLabel for="txtHoraAgendamento" value="#{messages.LABEL_HORARIO}:" styleClass="control-label required"/>
	                   <div class="controls">
						<p:inputText id="txtHoraAgendamento" value="#{acompanharChamadoController.agenda.horarioAgendamento}"
							label="#{messages.LABEL_DATA}" styleClass="input-medium">
							<f:convertDateTime pattern="HH:mm" />
						</p:inputText>
					</div>
				</div>
	
				<div class="control-group">
					<h:outputLabel for="txtEndereco" value="#{messages.LABEL_ENDERECO}:" styleClass="control-label required"/>
	                   <div class="controls">
						<p:inputText id="txtEndereco" value="#{acompanharChamadoController.agenda.endereco}"
							label="#{messages.LABEL_ENDERECO}" styleClass="input-xxlarge"/>
					</div>
				</div>

				<div class="form-actions">
					<p:commandButton id="btnSalvar" value="#{messages.BTN_SALVAR}" action="#{acompanharChamadoController.salvar()}" 
	                	update=":frmPesquisa" styleClass="btn" oncomplete="Util.scrollTop();" process="frmAgenda"/>
	                	
	                <p:commandButton value="#{messages.LABEL_CANCELAR}" styleClass="btn" type="button" onclick="modalAgenda.hide();"/>
				</div>
			</h:form>
		</p:dialog>
		<!-- End Dialog de confirmação ações -->
	</ui:define>
</ui:composition>